package cn.bgs.controller;


import cn.bgs.common.R;
import cn.bgs.pojo.Floor;
import cn.bgs.pojo.Portal;
import cn.bgs.service.IFloorService;
import cn.bgs.service.IPortalService;
import cn.bgs.vo.PortalVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import cn.bgs.common.R;
import cn.bgs.service.IPortalService;
import cn.bgs.vo.CommunityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 房屋表 前端控制器
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/portal")
public class PortalController {
    @Autowired
    private IPortalService iPortalService;

    @GetMapping({"findplot"})
    public R plot(){
        List<CommunityVo> communityVo = this.iPortalService.findplot();
        return R.ok().data("data", communityVo);
    }




    int a;

    @GetMapping("/appFindPortal/{floorId}")
    @ApiOperation(value = "app我的房屋(添加房屋的户号查询)")
    public R appFindPortal(@PathVariable Integer floorId){

        List<Portal> portal = iPortalService.appFindPortal(floorId);
        if (portal != null){
            return R.ok().data("portal",portal);
        }else {
            return R.error();
        }
    }
    @GetMapping({"delplot"})
    public R delplot(Integer id){
        this.iPortalService.delplot(id);
        return R.ok();
    }

    @PostMapping({"addcommunity"})
    public R addcommunity(@RequestBody CommunityVo forms){
        this.iPortalService.addcommunity(forms);
        return R.ok();
    }

    @PostMapping({"updatecommunity"})
    public R updatecommunity(@RequestBody CommunityVo forms){
        this.iPortalService.updatecommunity(forms);
        return R.ok();
    }





    @PostMapping("/appAddPortal")
    @ApiOperation(value = "app我的房屋(房屋信息添加)")
    public R appAddPortal(@RequestBody PortalVo portalVo){


        System.out.println("++++++"+portalVo.toString());


        portalVo.setUserId(a);

        System.out.println("pppppppppp"+portalVo.getUserId());
        System.out.println("aaaaaaaaaaaaa"+ a);

        if (portalVo.getBuildingId()!=null){
            iPortalService.addHouseId(portalVo);
            iPortalService.updateHouse(portalVo);
            return R.ok().message("修改成功");
        }else {
            return R.error().message("修改失败，信息有误或者验证码失效");
        }

    }


    @RequestMapping("/addHouseUser/{userId}")
    public void addHouseUser(@PathVariable("userId") Integer userId){

                  a=userId;

        System.out.println("+++++++++++++"+userId);

    }

    @PostMapping("/appFindMyhouse/{userId}")
    @ApiOperation(value = "app我的房屋(房屋信息查询)")
    public R appFindMyhouse(@PathVariable Integer userId){


        if (userId!=0){
         List<PortalVo> portal= iPortalService.appFindMyhouse(userId);
            return R.ok().message("修改成功").data("myhouseinfo",portal);
        }else {
            return R.error().message("修改失败，信息有误或者验证码失效");
        }

    }
    @PostMapping("/deleteMyhouse/{userId}")
    @ApiOperation(value = "app我的房屋(房屋信息查询)")
    public R deleteMyhouse(@PathVariable Integer userId){

        System.out.println("------------"+userId);

        if (userId!=0){
            iPortalService.deleteMyhouse(userId);
            return R.ok().message("删除成功");
        }else {
            return R.error().message("删除失败");
        }

    }





}

